<!DOCTYPE html>
<!-- 
Template Name: Metronic - Responsive Admin Dashboard Template build with Twitter Bootstrap 3.0
Version: 1.5
Author: KeenThemes
Website: http://www.keenthemes.com/
Purchase: http://themeforest.net/item/metronic-responsive-admin-dashboard-template/4021469?ref=keenthemes
-->
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
   <meta charset="utf-8" />
   <title>药店进销存管理系统 | 采购进货</title>
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta content="width=device-width, initial-scale=1.0" name="viewport" />
   <meta content="" name="description" />
   <meta content="" name="author" />
   <meta name="MobileOptimized" content="320">
   <!-- BEGIN GLOBAL MANDATORY STYLES -->          
   <link href="${base}/assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
   <link href="${base}/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
   <link href="${base}/assets/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css"/>
   <!-- END GLOBAL MANDATORY STYLES -->
   <!-- BEGIN PAGE LEVEL STYLES -->
   <link rel="stylesheet" type="text/css" href="${base}/assets/plugins/select2/select2_metro.css" />
   <link rel="stylesheet" href="${base}/assets/plugins/data-tables/DT_bootstrap.css" />
   <link rel="stylesheet" type="text/css" href="${base}/assets/plugins/fuelux/css/tree-metronic.css" />
   <!-- END PAGE LEVEL STYLES -->
   <!-- BEGIN THEME STYLES --> 
   <link rel="stylesheet" type="text/css" href="${base}/assets/plugins/bootstrap-datepicker/css/datepicker.css" />
   <link href="${base}/assets/css/style-metronic.css" rel="stylesheet" type="text/css"/>
   <link href="${base}/assets/css/style.css" rel="stylesheet" type="text/css"/>
   <link href="${base}/assets/css/style-responsive.css" rel="stylesheet" type="text/css"/>
   <link href="${base}/assets/css/plugins.css" rel="stylesheet" type="text/css"/>
   <link href="${base}/assets/css/themes/default.css" rel="stylesheet" type="text/css" id="style_color"/>
   <link href="${base}/assets/css/custom.css" rel="stylesheet" type="text/css"/>
   <!-- END THEME STYLES -->
   <link rel="shortcut icon" href="${base}/assets/img/favicon.ico" />
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed">
   <#include "header.ftl">
   <div class="clearfix"></div>
   <!-- BEGIN CONTAINER -->
   <div class="page-container">
      <!-- BEGIN SIDEBAR -->
      <div class="page-sidebar navbar-collapse collapse">
         <!-- BEGIN SIDEBAR MENU -->        
         <ul class="page-sidebar-menu">
            <li>
               <!-- BEGIN SIDEBAR TOGGLER BUTTON -->
               <div class="sidebar-toggler hidden-phone"></div>
               <!-- BEGIN SIDEBAR TOGGLER BUTTON -->
            </li>
            <li class="start">
		       <a href="${base}/admin/admin!main.action">
		       <i class="icon-home"></i> 
		       <span class="title">首页</span>
		       </a>
		    </li>
		    <li class="">
		       <a href="javascript:;">
		       <i class="icon-cogs"></i> 
		       <span class="title">业务中心</span>
		       <span class="arrow "></span>
		       </a>
		       <ul class="sub-menu">
		          <li class = "">
		             <a href="${base}/admin/admin!cashiering.action">消费收银</a>
		          </li>
		       </ul>
		    </li>
		    <li>
		       <a href="javascript:;">
		       <i class="icon-bookmark-empty"></i> 
		       <span class="title">会员管理</span>
		       <span class="arrow "></span>
		       </a>
		       <ul class="sub-menu">
		          <li >
		             <a href="${base}/admin/member!checkin.action">会员登记</a>
		          </li>
		          <li >
		             <a href="#memberInfo" data-toggle="modal">会员信息</a>
		          </li>
		          <li >
		             <a href="${base}/admin/member!memberLevel.action">会员级别</a>
		          </li>
		          <li>
		             <a href="${base}/admin/member!memberList.action">会员列表</a>
		          </li>
		       </ul>
		    </li>
		    <li class="active">
		       <a href="javascript:;">
		       <i class="icon-table"></i> 
		       <span class="title">库存管理</span>
		       <span class="selected "></span>
		       </a>
		       <ul class="sub-menu">
		          <li class = "active">
		             <a href="${base}/admin/admin!purchase.action">采购进货</a>
		          </li>
		          <li >
		             <a href="${base}/admin/admin!refund.action">退货换货</a>
		          </li>
		          <li >
		             <a href="${base}/admin/inventory!list.action">库存盘点</a>
		          </li>
		       </ul>
		    </li>
		    <li class="">
		       <a href="javascript:;">
		       <i class="icon-sitemap"></i> 
		       <span class="title">供应商管理</span>
		       <span class="arrow "></span>
		       </a>
		       <ul class="sub-menu">
		          <li >
		             <a href="${base}/admin/supplier!add.action">供应商录入</a>
		          </li>
		          <li >
		             <a href="${base}/admin/supplier!list.action">供应商列表</a>
		          </li>
		       </ul>
		    </li>
		    <li class="">
		       <a href="javascript:;">
		       <i class="icon-gift"></i> 
		       <span class="title">药品管理</span>
		       <span class="arrow "></span>
		       </a>
		       <ul class="sub-menu">
		          <li >
		             <a href="${base}/admin/medicine!add.action">药品录入</a>
		          </li>
		          <li >
		             <a href="${base}/admin/medicine!list.action">药品列表</a>
		          </li>
		       </ul>
		    </li>
		    <li>
		       <a href="javascript:;">
		       <i class="icon-user"></i> 
		       <span class="title">用户管理</span>
		       <span class="arrow "></span>
		       </a>
		       <ul class="sub-menu">
		          <li >
		             <a href="${base}/admin/user!add.action">用户录入</a>
		          </li>
		          <li >
		             <a href="${base}/admin/user!list.action">用户列表</a>
		          </li>
		       </ul>
		    </li>
		    <li>
		       <a href="javascript:;">
		       <i class="icon-user"></i> 
		       <span class="title">单据管理</span>
		       <span class="arrow "></span>
		       </a>
		       <ul class="sub-menu">
		          <li>
		             <a href="${base}/admin/admin!sellerRecordList.action">消费单据</a>
		          </li>
		          <li >
		             <a href="${base}/admin/admin!purchaseList.action">采购单据</a>
		          </li>
		          <li >
		             <a href="${base}/admin/admin!refundList.action">退货单据</a>
		          </li>
		       </ul>
		    </li>
		    <!-- 会员信息弹出框开始 -->
		    <#include "memberInfoDialog.ftl">
		    <!-- 会员信息弹出框结束  -->
         </ul>
         <!-- END SIDEBAR MENU -->
      </div>
      <!-- END SIDEBAR -->
      <!-- BEGIN PAGE -->
      <div class="page-content">
      	 <#include "changePassword.ftl">
         <#include "system-set.ftl">
         <!-- 读卡操作开始-->               
         <div id="jhDetail" class="modal fade" role="dialog" aria-hidden="true" data-backdrop="static" >
		    <div class="modal-dialog modal-wide">
		       <div class="modal-content">
		          <div class="modal-header">
		             <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
		             <h4 class="modal-title">编辑进货明细</h4>
		          </div>
		          <div class="modal-body">
		             <!-- BEGIN FORM-->
                      <form action="#" class="form-horizontal">
                         <div class="form-body">
                            <div class="row">
                               <div class="col-md-6">
                                  <div class="form-group">
                                     <label class="control-label col-md-3">编码</label>
                                     <div class="col-md-9">
                                        <input type="text" class="form-control " id="ypNo" disabled>
                                     </div>
                                  </div>
                               </div>
                               <!--/span-->
                               <div class="col-md-6">
                                  <div class="form-group">
                                     <label class="control-label col-md-3">名称</label>
                                     <div class="col-md-9">
                                        <input type="text" class="form-control " id="ypName" disabled>
                                     </div>
                                  </div>
                               </div>
                               <!--/span-->
                            </div>
                            <!--/row-->
                            <div class="row">
                               <div class="col-md-6">
                                  <div class="form-group">
                                     <label class="control-label col-md-3">进货店面</label>
                                     <div class="col-md-9">
                                        <input type="text" class="form-control " id = "jhStore" disabled>
                                     </div>
                                  </div>
                               </div>
                               <!--/span-->
                               <div class="col-md-6">
                                  <div class="form-group">
                                     <label class="control-label col-md-3">进货价格</label>
                                     <div class="col-md-9">
                                        <input type="text" class="form-control" id = "jhPrice">
                                     </div>
                                  </div>
                               </div>
                               <!--/span-->
                            </div>
                            <!--/row-->
                            <div class="row">
                               <div class="col-md-6">
                                  <div class="form-group">
                                     <label class="control-label col-md-3">批次码</label>
                                     <div class="col-md-9">
                                        <input type="text" class="form-control" placeholder="请输入本次进货的批次码" id = "jhPcm">
                                     </div>
                                  </div>
                               </div>
                               <!--/span-->
                               <div class="col-md-6">
                                  <div class="form-group">
                                     <label class="control-label col-md-3">进货数量</label>
                                     <div class="col-md-9">
                                        <input type="text" class="form-control" value ="1" id = "jhQuantity">
                                     </div>
                                  </div>
                               </div>
                               <!--/span-->
                            </div>
                            <!--/row-->
                            <div class="row">
                               <div class="col-md-6">
                                  <div class="form-group">
                                     <label class="control-label col-md-3">供应商</label>
                                     <div class="col-md-9">
	                                     <select class="form-control" name="jhSupplier" id="jhSupplier">
		                                    <option value="">请选择...</option>
		                                    <#if supplierList?exists>
				                                <#list supplierList as supplier>
				                                    <option value="${supplier.name}">${supplier.name}</option>
				                                </#list>
				                            </#if>
		                                 </select>
                                  	 </div>
                                  </div>
                               </div>
                               <div class="col-md-6">
                                  <div class="form-group">
                                     <label class="control-label col-md-3">备注</label>
                                     <div class="col-md-9">
                                        <textarea type="text" class="form-control" placeholder="最多输入200个字符" id = "bz"></textarea>
                                     </div>
                                  </div>
                               </div>
                            </div>
                         </div>
                      </form>
                      <!-- END FORM-->
		          </div>
		          <div class="modal-footer">
		             <button class="btn green" onclick= "return finished();">确定</button>
		             <button class="btn" data-dismiss="modal">取消</button>
		          </div>
		       </div>
		    </div>
		 </div>
         <!-- 读卡操作结束-->
         <!-- BEGIN PAGE HEADER-->
         <div class="row">
            <div class="col-md-12">
               <!-- BEGIN PAGE TITLE & BREADCRUMB-->
               <h5 class="page-title">
                  	采购进货 <small>这里对任何一个药品进行采购进货</small>
               </h5>
               <ul class="page-breadcrumb breadcrumb">
                  <li>
                     <i class="icon-home"></i>
                     <a href="index.html">Home</a> 
                     <i class="icon-angle-right"></i>
                  </li>
                  <li>
                     <a href="#">库存管理</a>
                     <i class="icon-angle-right"></i>
                  </li>
                  <li><a href="#">采购进货</a></li>
               </ul>
               <!-- END PAGE TITLE & BREADCRUMB-->
            </div>
         </div>
         <!-- END PAGE HEADER-->
         <!-- BEGIN PAGE CONTENT-->
         <div class="row">
           <div class="col-md-4 responsive" data-tablet="col-md-12 fix-offset" data-desktop="col-md-4">
               <!--BEGIN EXAMPLE TABLE PORTLET-->
               <div class="portlet box blue">
                  <div class="portlet-title">
                     <div class="caption" style="font-size:12px;"><i class="icon-medkit"></i>药品列表</div>
                     <div class="actions">
                        <a onclick = "return jhDetail();" class="btn blue" style="font-size:12px;"><i class="icon-edit"></i> 编辑进货明细</a>
                     </div>
                  </div>
                  <div class="portlet-body">
                     <table class="table table-striped table-bordered table-hover" id="medicineList">
                        <thead>
                           <tr>
                              <th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#medicineList .checkboxes" /></th>
                              <th style="font-size:12px;" class="hidden-480">名称</th>
                              <th style="font-size:12px;" class="hidden-480">单价</th>
                           </tr>
                        </thead>
                        <tbody>
                        	<#if medicineList?exists>
                        		<#list medicineList as medicine>
		                           <tr class="odd gradeX">
		                              <td><input type="checkbox" class="checkboxes" value="${medicine.id}" /></td>
		                              <td style="font-size:12px;">${medicine.name}</td>
		                              <td style="font-size:12px;">${medicine.retail_price}</td>
		                           </tr>
                           		</#list>
                           </#if>
                        </tbody>
                     </table>
                  </div>
               </div>
               <!-- END EXAMPLE TABLE PORTLET-->
            </div>
        	<div class="col-md-8 responsive" data-tablet="col-md-12 fix-offset" data-desktop="col-md-6">
               <!-- BEGIN EXAMPLE TABLE PORTLET-->
               <div class="portlet box blue">
                  <div class="portlet-title">
                     <div class="caption" style="font-size:12px;"><i class="icon-reorder"></i>进货列表</div>
                     <div class="actions">
                        <a href="javascript:;" onclick = "return djSubmit();" id = "djSubmit" class="btn blue"><i class="icon-save"></i> 提交</a>
                        <div class="btn-group">
                           <a class="btn blue" href="javascript:;" data-toggle="dropdown">
                           <i class="icon-cogs"></i> 工具
                           <i class="icon-angle-down"></i>
                           </a>
                           <ul class="dropdown-menu pull-right">
                              <li><a href="javascript:;" onclick = "return djImport();" id = "djImport"><i class="icon-signin"></i> 单据导入</a></li>
                              <li><a href="javascript:;" onclick = "return clearOut();"><i class="icon-trash"></i> 清空列表</a></li>
                           </ul>
                        </div>
                     </div>
                  </div>
                  <div class="portlet-body">
                     <table class="table table-striped table-bordered table-hover" id="jhList">
                        <thead>
                           <tr>
                           	  <th class="hidden-480">药品编码</th>
                              <th class="hidden-480">药品名称</th>
                              <th class="hidden-480">进货店面</th>
                              <th class="hidden-480">进货价格</th>
                              <th class="hidden-480">进货数量</th>
                              <th class="hidden-480">备注</th>
                              <th class="hidden-480">操作</th>
                           </tr>
                        </thead>
                        <tbody>
                        </tbody>
                     </table>
                  </div>
               </div>
               <!-- END EXAMPLE TABLE PORTLET-->
            </div>
         </div>
         <!-- END PAGE CONTENT-->
      </div>
      <!-- END PAGE -->
   </div>
   <!-- END CONTAINER -->
   <!-- BEGIN FOOTER -->
   <div class="footer">
      <div class="footer-inner">
         2014 &copy; 西南财经大学天府学院  | 袁金廷
      </div>
      <div class="footer-tools">
         <span class="go-top">
         <i class="icon-angle-up"></i>
         </span>
      </div>
   </div>
   <!-- END FOOTER -->
   <!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
   <!-- BEGIN CORE PLUGINS -->   
   <!--[if lt IE 9]>
   <script src="${base}/assets/plugins/respond.min.js"></script>
   <script src="${base}/assets/plugins/excanvas.min.js"></script> 
   <![endif]-->   
   <script src="${base}/assets/plugins/jquery-1.10.2.min.js" type="text/javascript"></script>
   <script src="${base}/assets/plugins/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>    
   <script src="${base}/assets/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
   <script src="${base}/assets/plugins/bootstrap-hover-dropdown/twitter-bootstrap-hover-dropdown.min.js" type="text/javascript" ></script>
   <script src="${base}/assets/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
   <script src="${base}/assets/plugins/jquery.blockui.min.js" type="text/javascript"></script>  
   <script src="${base}/assets/plugins/jquery.cookie.min.js" type="text/javascript"></script>
   <script src="${base}/assets/plugins/uniform/jquery.uniform.min.js" type="text/javascript" ></script>
   <!-- END CORE PLUGINS -->
   <!-- BEGIN PAGE LEVEL PLUGINS -->
   
   <script type="text/javascript" src="${base}/assets/plugins/select2/select2.min.js"></script>
   <script type="text/javascript" src="${base}/assets/plugins/data-tables/jquery.dataTables.js"></script>
   <script type="text/javascript" src="${base}/assets/plugins/data-tables/DT_bootstrap.js"></script>
   <script type="text/javascript" src="${base}/assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
   <script type="text/javascript" src="${base}/assets/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
   <!-- END PAGE LEVEL PLUGINS -->
   <!-- BEGIN PAGE LEVEL SCRIPTS -->
   <script src="${base}/assets/scripts/app.js"></script>
   <script src="${base}/resources/scripts/purchase-managed.js"></script>
   <script>
      jQuery(document).ready(function() {       
         App.init();
         CashieringManaged.init();
      });
      
       /**
      	弹出编辑进货明细窗口
      */
      function jhDetail(){
      	var flag = "false";
      	var idValue=""; //选中的药品id
		$("#medicineList tbody :checkbox").each(function(i){
			if($(this).attr("checked")=="checked"){
				flag = "true";//设置标志为true，表示选中了至少一条数据
				var medicineId = $(this).val();//获得当前遍历的第一个数据的id
				idValue = medicineId;//把选中的id,存放在字符串中.便于传递到后台
			}
		});
		if(flag=="false"){
			alert("没 有 选 中 药 品 ! 请 选 择 药 品 !");
		}else{
			$.ajax({
	            type:"post",
	            url:"/pims/admin/admin!findById.action",
	            dataType:"json",
	            data:"medicineId="+idValue,
	            cache:false,
	            beforeSend:function(XMLHttpRequest){
	            },
	            success:function(json){
	            	medicine = json.medicine;
	            	storename = json.storename;
	            	$("#ypNo").val(medicine.no);
	            	$("#ypName").val(medicine.name);
	            	$("#jhStore").val(storename);
	            	$("#jhPrice").val(medicine.purchase_price);
	            	$("#jhQuantity").val(1);
	            	$("#jhSupplier").val("");
	            	$("#bz").val("");
	            	$("#jhPcm").val("");
	            	$("#jhDetail").modal("show");
	            },
	           	complete:function(XMLHttpRequest,textStatus){
	           	},
	          	error:function(XMLHttpRequest,textStatus,errorThrown){
	                   alert("网络错误，请稍后重试");
	          	}
            });
		}
      				
      }
      /**
      	清空列表
      */
      function clearOut(){
      	$("#jhList tbody tr").remove();
      }     
      /**
      	删除列表中的某行数据
      */
      function trash(td){
      	$(td).parents('tr').remove();
      }
      /**
      	重新编辑列表中的某行数据
      */
      function	edit(td){
      	var tr = $(td).parents('tr');
      	$("#jhSupplier").val(tr.find("#gys").val());
      	$("#jhPcm").val(tr.find("#pcm").val());
      	$("#ypNo").val(tr.find("#ypbm").html());
    	$("#ypName").val(tr.find("#ypmc").html());
    	$("#jhStore").val(tr.find("#jhdm").html());
    	$("#jhPrice").val(tr.find("#jhjg").html());
    	$("#jhQuantity").val(tr.find("#jhsl").html());
    	$("#bz").val(tr.find("#remarks").html());
    	$("#jhDetail").modal("show");
      }
      /**
      	把编辑好的药品进货明细提交到待进货的进货列表
      */
      function finished(){
      	var pcm = $("#jhPcm").val();
      	if(pcm == ""){
      		alert("请输入批次码");
      		return false;
      	}
        var ypbm = $("#ypNo").val();
    	var ypmc = $("#ypName").val();
    	var jhdm = $("#jhStore").val();
    	var jhjg = $("#jhPrice").val();
    	var jhsl = $("#jhQuantity").val();
    	var gys = $("#jhSupplier").val();
    	var bz = $("#bz").val();
    	$( "#jhList tbody" ).append( "<tr>" +
    	  '<input type="hidden" id = "gys" value = '+ gys + '>' +
    	  '<input type="hidden" id = "pcm" value = '+ pcm + '>' +
          '<td id = "ypbm">' + ypbm + "</td>" +
          '<td id = "ypmc">' + ypmc + "</td>" +
          '<td id = "jhdm">' + jhdm + "</td>" +
          '<td id = "jhjg">' + jhjg + "</td>" +
          '<td id = "jhsl">' + jhsl +"</td>" +
          '<td id = "remarks">' + bz +"</td>" +
          '<td>'+
          	'<a onclick = "trash(this);" class="btn blue btn-xs black">'+'<i class="icon-trash">'+'</i>Delete</a>'+
          '</td>'+
        "</tr>" );
        /**
        	添加到列表之后，把药品改成不选择状态
        */
        $('#medicineList tbody tr .checkboxes').each(function(){
        	$(this).parents("span").removeAttr("class");
        	$(this).attr("checked",false);
        });
        $("#djSubmit").removeClass("disabled");
    	$("#jhDetail").modal("hide");
      }
      /**
      	提交进货明细
      */
      function djSubmit() {
      	if($('#jhList tbody tr').length <= 0){
      		alert("没有可提交的数据");
      		return false;
      	}
            var tableString = "";//定义一个字符串，存放表中所有数据
	  		$('#jhList tbody tr').each(function(ri){
	  			var trString = "";//定义一个字符串，存放行中所有数据
	  			$(this).each(function(di){
	  				trString = $(this).find("#pcm").val();
	  				trString = trString + "," + $(this).find("#gys").val();
	  				trString = trString + "," + $(this).find("#ypbm").html();
					trString = trString + "," + $(this).find("#ypmc").html();
					trString = trString + "," + $(this).find("#jhdm").html();
					trString = trString + "," + $(this).find("#jhjg").html();
					trString = trString + "," + $(this).find("#jhsl").html();
					if($(this).find("#remarks").html()==""){
						remarks = "无"
					}
					trString = trString + "," + remarks;
				});
				tableString = trString + ";" + tableString;
	        });
	        
	        $.ajax({
	            type:"post",
	            url:"/pims/admin/admin!doCgjh.action",
	            dataType:"json",
	            data:"jhList="+tableString,
	            cache:false,
	            beforeSend:function(XMLHttpRequest){
	            },
	            success:function(json){
	            	result = json.result;
	            	if(result){
	            		$("#jhList tbody tr").remove();
	            		alert("操作成功");
	            	}else{
	            		alert("操作失败");
	            	}
	            },
	           	complete:function(XMLHttpRequest,textStatus){
	           	},
	          	error:function(XMLHttpRequest,textStatus,errorThrown){
	                   alert("网络错误，请稍后重试");
	          	}
	        });
	        return false;
      }
    	/**
        	获取购物车的所有数据，设置总数量和总金额
        */
        function setTotal(){
	        var total_Amount = 0;//总数量
	        var total_Money = 0; //总金额
	        $('#costInfo tbody tr').each(function (i) {
				total_Amount = $(this).find("#amount").html()*1+total_Amount*1;
				total_Money = $(this).find("#discountTotal").html()*1+total_Money*1;
	        });
	        $("#totalAmount").html(total_Amount);
			$("#totalMoney").html(total_Money);
        }
   </script>
</body>
<!-- END BODY -->
</html>